<?php /* SVN: $Id: admin_index.ctp 2741 2010-08-13 15:30:58Z boopathi_026ac09 $ */ ?>
<div class="home-page-block js-response">
<div class="content-info master-page-info1">
<p><?php echo __l("As per the information we received from PayPal, websites should never
aggregate money from users (i.e., have wallet option) and PayPal
suggests that we use Adaptive Payment API with primary receiver set to
Project Owner (not Site) for chargeback responsibility reasons.
Violating these instructions may lead to account seizure from PayPal.
So, we've used PayPal Adaptive preapproval and chained API. In this
workflow, amount will be authorized (not captured) from Backer once
he pledges. After the goal reached/tipping point, the pledged amount
will be charged/captured; site fee/commission will also be charged at
this time from Project Owner."); ?></p>
<p><?php echo __l("Caveat of this workflow: Backer has an option in his PayPal account to
cancel preapproval payments. If he does so, this software detects it
through PayPal IPN and cancels the pledge with 'Voided' status. But,
this may give room for unstable projects. Also, if Backer doesn't have
enough balance in the final settlement (when site tries to charge on
tipping point), it may fail."); ?></p>
<p><?php echo __l("<em>However</em>, we understand that some sites have Wallet option
through special relationships with PayPal. But, we <em>seriously</em>
warn you not to enable Wallet when using PayPal. In this software,
Wallet option is provided as a provision to integrate other payment
gateways solutions.");?></p>
<div class="clearfix"><span><?php echo __l("--Agriya");?></span></div></div>

<?PHP 
    unset($wallet_enabled);
    unset($paypal_enabled);
    foreach ($paymentGateways as $paymentGateway1):
      if($paymentGateway1['PaymentGateway']['id'] == ConstPaymentGateways::Wallet):
         if($paymentGateway1['PaymentGateway']['is_active'] == '1')
         {
            $wallet_enabled = $paymentGateway1['PaymentGateway']['is_active'];
         }
      endif;
      if($paymentGateway1['PaymentGateway']['id'] == ConstPaymentGateways::PayPal):
         if($paymentGateway1['PaymentGateway']['is_active'] == '1')
         {
            $paypal_enabled = $paymentGateway1['PaymentGateway']['is_active'];
         }
      endif;
    endforeach;?>
   


<?PHP
   $message = '';
   $payment_class = '';
   if(isset($wallet_enabled) && isset($paypal_enabled)) {
    $message = __l('Read the warning carefully and enable appropriate options for your website.');
    $payment_class = "content-info master-page-info1";
} else if(isset($wallet_enabled) && (!isset($paypal_enabled))) {
   $message = __l('Site cannot work with "Wallet" option alone. This is added as
a provision to integrate other payment gateway solutions.');
   $payment_class = "content-info master-page-info1";
 } else if(isset($paypal_enabled) && (!isset($wallet_enabled))) {
$message = __l("Read the warning carefully. PayPal Adaptive is recommended by PayPal, but read the caveats and
understand clearly.");
   $payment_class = "content-info master-page-info";
   } else if(!isset($paypal_enabled) && (!isset($wallet_enabled))) {
$message = __l("Site cannot work without enabling anyone of the payment gateways.");
   $payment_class = "content-info master-page-info1";
   }
?>


<div id = "payment_msg" class="<?PHP echo $payment_class; ?>"><?PHP echo $message; ?></div>




<div><?php echo $this->element('paging_counter');?></div>
<table class="list">
    
    <tr>
        <th rowspan="3" class="actions"><?php echo __l('Actions');?></th>
        <th rowspan="3"><?php echo $this->Paginator->sort(__l('display_name'));?></th>
		<th colspan="6"><?php echo __l('Settings');?></th>
    </tr>
	<tr>
        <th rowspan="2"><?php echo __l('Active');?></th>
		<th rowspan="2"><?php echo __l('Live Mode');?></th>
        <th colspan="4"><?php echo __l('Where to use?');?></th>
    </tr>
	<tr>
		<th><?php echo __l('Payout');?></th>
		<th><?php echo __l('Add to Wallet');?></th>
		<th><?php echo __l('Project');?></th>
		<th><?php echo __l('Pledge');?></th>
		
		 
    </tr>
<?php
if (!empty($paymentGateways)):

$i = 0;
foreach ($paymentGateways as $paymentGateway):
	$class = null;
	$status_class = null;
	if ($i++ % 2 == 0) :
		$class = ' class="altrow"';
	endif;
?>
	<tr<?php echo $class;?>>
  <td class="actions dl">
            <div class="action-block">
                <span class="action-information-block">
                    <span class="action-left-block">&nbsp;&nbsp;</span>
                        <span class="action-center-block">
                            <span class="action-info">
                                <?php echo __l('Action');?>
                             </span>
                        </span>
                    </span>
                    <div class="action-inner-block">
                    <div class="action-inner-left-block">
                        <ul class="action-link clearfix">
					<li><?php echo $this->Html->link(__l('Edit'), array('action' => 'edit', $paymentGateway['PaymentGateway']['id']), array('class' => 'edit js-edit', 'title' => __l('Edit')));?></li>

	                		 </ul>
    					</div>
    					<div class="action-bottom-block"></div>
    				  </div>
              </div>
        </td>
		<td class="dl">
           <?php echo $this->Html->cText($paymentGateway['PaymentGateway']['name']);?>
           <span class="info">
             <?php echo $this->Html->cText($paymentGateway['PaymentGateway']['description']);?>
           </span>
        </td>
        <td id='payment-id<?php echo $paymentGateway['PaymentGateway']['id']?>' class='<?php echo "admin-status-".$paymentGateway['PaymentGateway']['is_active']?> <?php echo ($paymentGateway['PaymentGateway']['is_active'] ==1)? 'js-active-gateways': 'js-deactive-gateways'; ?>'><?php echo $this->Html->link(($paymentGateway['PaymentGateway']['is_active'] ==1)? "Yes": "No", array('action'=>'update', $paymentGateway['PaymentGateway']['id'], ConstPaymentGateways::Active, 'toggle' => ($paymentGateway['PaymentGateway']['is_active'] ==1)? 0: 1),array('class'=>'js-admin-update-status'));?>
		</td>
		<?php if($paymentGateway['PaymentGateway']['id'] != ConstPaymentGateways::Wallet): ?>
		<td class='<?php echo "admin-status-".(($paymentGateway['PaymentGateway']['is_test_mode'] ==1)? 0: 1); ?>'><?php echo $this->Html->link(($paymentGateway['PaymentGateway']['is_test_mode'] ==1)? "No": "Yes", array('action'=>'update', $paymentGateway['PaymentGateway']['id'], ConstPaymentGateways::Testmode, 'toggle' => ($paymentGateway['PaymentGateway']['is_test_mode'] ==1)? 0: 1),array('class'=>'js-admin-update-status'));?>
		</td>
		<?php else: ?>
			<td class="dc"><?php echo '-'; ?>
			</td>
		<?php endif; ?>
		<?php if($paymentGateway['PaymentGateway']['id'] == ConstPaymentGateways::PayPal): ?>
		<td>
		<span id="tip2" class="js-helptip" title="<?php echo __l("Payout is automatically handled."); ?>">n/a</span>
		</td>
			<?php else: ?>
			<td class="dc"><?php echo '-'; ?>
			</td>
		<?php endif; ?>
		<?php
        unset($project_enabled);
		unset($pledge_enabled);
		unset($wallet_enabled);
		foreach($paymentGateway['PaymentGatewaySetting'] as $paymentGatewaySetting):
           if($paymentGatewaySetting['key'] == 'is_enable_for_project'):
              $project_enabled = $paymentGatewaySetting['test_mode_value'];
           endif;
           if($paymentGatewaySetting['key'] == 'is_enable_for_pledge'):
              $pledge_enabled = $paymentGatewaySetting['test_mode_value'];
           endif;
           if($paymentGatewaySetting['key'] == 'is_enable_for_add_to_wallet'):
              $wallet_enabled = $paymentGatewaySetting['test_mode_value'];
           endif;
		endforeach;
		?>
		<?PHP if(!isset($wallet_enabled)){ ?> <td>-</td><?PHP } else{ ?>
		<td class='<?php echo "admin-status-".$wallet_enabled; ?>'>
		    n/a
		</td>
		<?PHP } ?>
        <td class='<?php echo "admin-status-".$project_enabled; ?>'>
            <?php echo $this->Html->link(($project_enabled ==1)? "Yes": "No", array('action'=>'update', $paymentGateway['PaymentGateway']['id'], ConstPaymentGateways::Project, 'toggle' => ($project_enabled ==1)? 0: 1),array('class'=>'js-admin-update-status'));?>
		</td>
		<td class='<?php echo "admin-status-".$pledge_enabled; ?>'>
            <?php echo $this->Html->link(($pledge_enabled ==1)? "Yes": "No", array('action'=>'update', $paymentGateway['PaymentGateway']['id'], ConstPaymentGateways::Pledge, 'toggle' => ($pledge_enabled ==1)? 0: 1),array('class'=>'js-admin-update-status'));?>
		</td>
	</tr>
<?php
    endforeach;
else:
?>
	<tr>
		<td colspan="9" class="notice"><?php echo __l('No Payment Gateways available');?></td>
	</tr>
<?php
endif;
?>
</table>
<?php if (!empty($paymentGateways)): ?>
	<div><?php echo $this->element('paging_links'); ?></div>
<?php endif; ?>
</div>